package com.diandi.messages.utils.http;

import com.alibaba.fastjson.JSONArray;
import com.diandi.messages.tools.CreateTradeNo;
import com.diandi.messages.tools.GsonUtil;
import org.apache.commons.lang3.StringUtils;

import java.util.*;

/**
 *  用于签章<根据模板类型来签章>
 * @author mwz
 * @create 2017-08-23 13:11
 * @version V1.0.0
 */
public class FddContractSignatureTools {

    /*public static Map<String, Object> genContractParamMap(String contractType, String params){
        Map<String, Object> returnMap = new HashMap<String, Object>();

        if (contractType.equals(ContractTypeAndTempName.借款协议.getType())){
            returnMap = genLoanMap(params);
            return returnMap;
        }
        if (contractType.equals(ContractTypeAndTempName.信息咨询与管理服务协议.getType())){
            returnMap = genInforServiceMap(params);
            return returnMap;
        }
        if (contractType.equals(ContractTypeAndTempName.借款人承诺书.getType())){
            returnMap = genLetterOfCommitmentMap(params);
            return returnMap;
        }
        if (contractType.equals(ContractTypeAndTempName.债券转让协议.getType())){
            returnMap = genBondTransferMap(params);
            return returnMap;
        }
        if (contractType.equals(ContractTypeAndTempName.授权委托协议.getType())){
            returnMap = genDelegationMap(params);
            return returnMap;
        }
        if (contractType.equals(ContractTypeAndTempName.委托代扣协议_循环贷.getType())){
            returnMap = genEntrustWithHoldMap(params);
            return returnMap;
        }

        returnMap.put("responseCode", "QZ_7007");
        returnMap.put("responseMsg", "合同类型不合法");

        return returnMap;
    }*/

    /**
     * 生成债券转让协议参数
     * @param params
     * @return
     */
    /*public static Map genBondTransferMap(String params){
        Map returnMap = null;

        Map<String, Object> paramMapObj = new HashMap<String, Object>();
        Map<String, String> paramMap = GsonUtil.fronJson2Map(params);
        returnMap = CheckParams.checkParamsIsExist(paramMap, "assignorList", "assigneeName", "assigneeIdNo",
                "assigneeAddress", "assigneePhone", "obligorName", "obligorIdNo", "bondAmount", "bondAmountCapital", "loanDays",
                "loanStartDate", "loanEndDate", "assigneeCustomerId", "assigneeSignDate");

        if (returnMap != null && !returnMap.isEmpty()){
            return returnMap;
        }

        JSONArray assignorArray = JSONArray.parseArray(paramMap.get("assignorList"));
        List<Map<String, String>> assignorList = new ArrayList<Map<String, String>>();

        for (Object assignor : assignorArray) {
            Map assignorMap = GsonUtil.fronJson2Map(assignor.toString());
            returnMap = CheckParams.checkParamsIsExist(assignorMap, "name", "idenType", "identNo", "customerId", "signDate");
            if (returnMap != null && !returnMap.isEmpty()){
                return returnMap;
            }
            assignorList.add(assignorMap);
        }

        Set<String> keys = paramMap.keySet();
        for (String key : keys) {
            paramMapObj.put(key, paramMap.get(key));
        }

        if (!paramMapObj.containsKey("contractNo") || StringUtils.isBlank(paramMapObj.get("contractNo").toString())){
            paramMapObj.put("contractNo", CreateTradeNo.createTradeNo("M4"));
        }

        paramMapObj.put("assignorList", assignorList);

        return paramMapObj;
    }*/

    /**
     * 生成授权委托协议参数
     * @param params
     * @return
     */
    /*public static Map genDelegationMap(String params){
        Map returnMap = new HashMap();
        Map paramMap = GsonUtil.fronJson2Map(params);
        returnMap = CheckParams.checkParamsIsExist(paramMap, "licensorName", "licensorIdNo", "licensorAddress", "licensorPhone",
                "licensorEmail", "licenseeName", "licenseeIdNo", "licenseeAddress", "licenseePhone","licensorCustomerId", "licenseeCustomerId",
                "licensorDate", "licenseeDate");

        if (returnMap != null && !returnMap.isEmpty()){
            return returnMap;
        }

        if (!paramMap.containsKey("contractNo") || StringUtils.isBlank(paramMap.get("contractNo").toString())){
            paramMap.put("contractNo", CreateTradeNo.createTradeNo("M5"));
        }

        return paramMap;
    }*/

    /**
     * 生成委托代扣协议参数
     * @param params
     * @return
     */
    /*public static Map genEntrustWithHoldMap(String params){
        Map returnMap = new HashMap();
        Map paramMap = GsonUtil.fronJson2Map(params);
        returnMap = CheckParams.checkParamsIsExist(paramMap, "bName", "bIdNo", "aCustomerId", "bCustomerId", "aSignDate", "bSignDate");

        if (returnMap != null && !returnMap.isEmpty()){
            return returnMap;
        }
        if (!paramMap.containsKey("contractNo") || StringUtils.isBlank(paramMap.get("contractNo").toString())){
            paramMap.put("contractNo", CreateTradeNo.createTradeNo("M6"));
        }

        return paramMap;
    }*/

    /**
     * 生成信息咨询与管理服务协议参数
     * @param params
     * @return
     */
    /*public static Map genInforServiceMap(String params){
        Map returnMap = null;
        Map paramMap = GsonUtil.fronJson2Map(params);
        returnMap = CheckParams.checkParamsIsExist(paramMap, "borrowerName", "borrowerIdNo", "borrowerAddress",
                "borrowerPhone", "borrowerEmail", "feeCapital", "feeLower", "borrowerCustomerId", "signDate");
        if (returnMap != null && !returnMap.isEmpty()){
            return returnMap;
        }

        if (!paramMap.containsKey("contractNo") || StringUtils.isBlank(paramMap.get("contractNo").toString())){
            paramMap.put("contractNo", CreateTradeNo.createTradeNo("M2"));
        }
        return paramMap;
    }*/

    /**
     * 生成借款人承诺书参数
     * @param params
     * @return
     */
    /*public static Map genLetterOfCommitmentMap(String params){
        Map returnMap = null;
        Map paramMap = GsonUtil.fronJson2Map(params);
        returnMap = CheckParams.checkParamsIsExist(paramMap, "borrowerName", "borrowerIdNo", "borrowerAddress",
                "borrowerPhone", "borrowerEmail", "borrowerCustomerId", "signDate");
        if (returnMap != null && !returnMap.isEmpty()){
            return returnMap;
        }

        if (!paramMap.containsKey("contractNo") || StringUtils.isBlank(paramMap.get("contractNo").toString())){
            paramMap.put("contractNo", CreateTradeNo.createTradeNo("M3"));
        }

        return paramMap;
    }*/


    /**
     * 生成借款协议参数
     * @param params
     * @return
     */
    /*public static Map genLoanMap(String params){
        Map<String, String> returnMap = null;
        Map<String, String> paramMap = GsonUtil.fronJson2Map(params);
        Map<String, Object> paramMapObj = new HashMap<String, Object>();
        returnMap = CheckParams.checkParamsIsExist(paramMap, "apr", "borrowerAddress", "borrowerEmail",
                "borrowerID", "borrowerName", "borrowerPhone", "borrowerCustomerId", "borrowerSignDate", "lenderInfoList",
                "loanDays", "loanEndDay", "loanPrincipleCaptal", "loanPrincipleLower", "loanStartDay", "repayDetailList", "repayInsterest",
                "repayType", "totalInterest", "totalLoanAmount", "totalPrincipal");

        if (returnMap != null && !returnMap.isEmpty()){
            return returnMap;
        }

        JSONArray lenderInfoArray = JSONArray.parseArray(paramMap.get("lenderInfoList"));
        List<Map<String, String>> lenderInfoList = new ArrayList<Map<String, String>>();
        Map<String, String> lenderInfoMap = null;
        for (Object lenderInfo : lenderInfoArray) {
            lenderInfoMap = GsonUtil.fronJson2Map(lenderInfo.toString());
            returnMap = CheckParams.checkParamsIsExist(lenderInfoMap, "identNo", "identType", "interest", "lenderSignDate",
                    "lenderCustomerId", "loanAmount", "name", "principal");
            if (returnMap != null && !returnMap.isEmpty()){
                return returnMap;
            }
            lenderInfoList.add(lenderInfoMap);
        }

        JSONArray repayDetailArray = JSONArray.parseArray(paramMap.get("repayDetailList"));
        List<Map<String, String>> repayDetailList = new ArrayList<Map<String, String>>();
        Map<String, String> repayDetailMap = null;
        for (Object repayDetail : repayDetailArray) {
            repayDetailMap = GsonUtil.fronJson2Map(repayDetail.toString());
            returnMap = CheckParams.checkParamsIsExist(repayDetailMap, "lastAmount", "repayDate", "repayInsterest", "repayPrincipal", "totalRepay");
            if (returnMap != null && !returnMap.isEmpty()){
                return returnMap;
            }
            repayDetailList.add(repayDetailMap);
        }

        Set<String> paramKeys = paramMap.keySet();
        for (String key : paramKeys) {
            paramMapObj.put(key, paramMap.get(key));
        }

        if (!paramMap.containsKey("contractNo") || StringUtils.isBlank(paramMap.get("contractNo").toString())){
            paramMapObj.put("contractNo", CreateTradeNo.createTradeNo("M1"));
        }

        paramMapObj.put("lenderInfoList", lenderInfoList);
        paramMapObj.put("repayDetailList", repayDetailList);

        return paramMapObj;
    }*/
}
